#ifndef _LOGFILE_H
#define _LOGFILE_H

#include "AppendFile.h"
#include "mutex.h"
#include <memory>

namespace droneswarm
{
    class LogFile
    {
    public:
        LogFile( std::string baseName, int flushEveryN = 1024 );
        ~LogFile();

        //将日志写入文件,这个方法是对AppendFile进行操作的封装
        void append( const char *logline, int len );

        //刷新缓冲区
        void flush();


    private:
        void append_unlocked( const char *logline, int len );

        //属性
        const std::string baseName_;
        //触发刷新的阈值
        const int flushEveryN_;
        //记录当前写入的次数
        int count_;

        //定义锁
        std::unique_ptr< monsoon::RWMutex > mutex_;
        //定义操作的appendFile类
        std::unique_ptr< AppendFile > file_;

    private:
        LogFile( const LogFile & ) = delete;
        LogFile( const LogFile && ) = delete;
        LogFile &operator=( const LogFile & ) = delete;
    };
}  // namespace droneswarm

#endif